﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using BUS;
using DTO;

namespace GUI
{
    public partial class FrmInHoaDon : Form
    {
        public FrmInHoaDon()
        {
            InitializeComponent();
        }

        private void FrmInHoaDon_Load(object sender, EventArgs e)
        {
            LoadDanhSachBanBan();
            // TODO: This line of code loads data into the 'QLNHCDataSet.ChiTietHoaDon' table. You can move, or remove it, as needed.

        }

        private void LoadDanhSachBanBan()
        {
            BanBUS banBUS = new BanBUS();
            cbxBan.DataSource = banBUS.laydanhsachbantheotrangthai("Bận");
            cbxBan.ValueMember = "MaBan";
            cbxPTXL.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.ChiTietHoaDonTableAdapter.Fill(this.QLNHCDataSet.ChiTietHoaDon, cbxBan.SelectedValue.ToString());
            this.reportViewer1.RefreshReport();
        }

        private void FrmInHoaDon_FormClosed(object sender, FormClosedEventArgs e)
        {
            Program.frm_manhinhchinh.sub_mn_inhoadon.Checked = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (cbxPTXL.SelectedIndex == 0)//in và lưu
            {
                HoaDonDTO hddto = new HoaDonDTO();
                HoaDonBUS hdbus = new HoaDonBUS();
                hddto.MaHD = hdbus.LayMaHDTheoBanChuaTinhTien(cbxBan.SelectedValue.ToString());
                hddto.GioRa = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
                hddto.TenUser = User.TenUser;
                hddto.TinhTrangHD = "Chưa tính tiền";
                hdbus.CapNhatHoaDon(hddto);
                int kq = hdbus.DaThanhToanHoaDon(cbxBan.SelectedValue.ToString());
                if (kq == 1)
                {
                    MessageBox.Show("In hóa đơn thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("In hóa đơn thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            LoadDanhSachBanBan();
            PrintDialog prtdig = new PrintDialog();
            prtdig.ShowDialog();
        }

    }
}
